package data.features;

import java.util.List;
import java.util.UUID;

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBIgnore;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBRangeKey;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable;

import data.dynamodbfunctions.Persistence_Helper_FeatureAssociation;
import data.exceptions.Dynamo_DB_Functions_Exception;
import data.meta.MetaAnnotations.MetaParam;
import data.meta.Metadata;
import data.objects.ClassSpy;
/* @author Robin
*
*/
@DynamoDBTable(tableName="CC_FeatureAssociation")
public class FeatureAssociation {
	
	public String TenantID;
	public String ID;
	public String type;
	public String sourceFeatureID;
	public String targetFeatureID;
	
	public FeatureAssociation() {
		this.ID = ""+UUID.randomUUID();
	}

	public FeatureAssociation(String TenantID, String type,
			String sourceFeatureID, String targetFeatureID) {
		super();
		this.TenantID = TenantID;
		this.ID =""+UUID.randomUUID();
		this.type = type;
		this.sourceFeatureID = sourceFeatureID;
		this.targetFeatureID = targetFeatureID;
	}

	@DynamoDBHashKey(attributeName="ID")
	public String getTenantID() {return TenantID;}
	public void setTenantID(String TenantID) {this.TenantID = TenantID;}

	@DynamoDBRangeKey(attributeName="Range_ID")
	public String getFeatureAssociationID() {return ID;}
	public void setFeatureAssociationID(String ID) {this.ID = ID;}
	
	@DynamoDBAttribute(attributeName="Type")
	public String getType() {return type;}
	public void setType(String type) {this.type = type;}

	@DynamoDBAttribute(attributeName="SourceFeatureID")
	public String getSourceFeatureID() {return sourceFeatureID;}
	public void setSourceFeatureID(String sourceFeatureID) {this.sourceFeatureID = sourceFeatureID;}

	@DynamoDBAttribute(attributeName="TargetFeatureID")
	public String getTargetFeatureID() { return targetFeatureID;}
	public void setTargetFeatureID(String targetFeatureID) {this.targetFeatureID = targetFeatureID;}
	
//	@MetaMethod
	@DynamoDBIgnore
	public static FeatureAssociation create(@MetaParam("TenantID") String TenantID, @MetaParam("type") String type, @MetaParam("sourceFeatureID") String sourceFeatureID, @MetaParam("targetFeatureID") String targetFeatureID) throws Dynamo_DB_Functions_Exception {
		FeatureAssociation createFeature = new FeatureAssociation(TenantID, type, sourceFeatureID, targetFeatureID);
		return Persistence_Helper_FeatureAssociation.getInstance().create(createFeature);	
	}
	
//	@MetaMethod
	@DynamoDBIgnore
	public static FeatureAssociation read(@MetaParam("TenantID") String tenant_id, @MetaParam("id") String id) throws Dynamo_DB_Functions_Exception {
		FeatureAssociation readobject=Persistence_Helper_FeatureAssociation.getInstance().read(tenant_id,id);
		return readobject;
	}
	
//	@MetaMethod
	@DynamoDBIgnore
	public static List<FeatureAssociation> readAll(@MetaParam("TenantID") String tenant_id) throws Dynamo_DB_Functions_Exception {
		List<FeatureAssociation> readobject=Persistence_Helper_FeatureAssociation.getInstance().readAllwithHashKey(tenant_id);
		return readobject;
	}
	
//	@MetaMethod
	@DynamoDBIgnore
	public static FeatureAssociation update(@MetaParam("TenantID") String tenant_id, @MetaParam("ID") String ID, 
			@MetaParam("type") String type, @MetaParam("sourceFeatureID") String sourceFeatureID, @MetaParam("targetFeatureID") String targetFeatureID) throws Dynamo_DB_Functions_Exception {
		System.out.println("FeatureAssociationID = "+ ID);
		FeatureAssociation updateFeature =Persistence_Helper_FeatureAssociation.getInstance().read(tenant_id,ID);
		if(!"".equals(type)){
			updateFeature.setType(type);
		}
		if(!"".equals(sourceFeatureID)){
			updateFeature.setSourceFeatureID(sourceFeatureID);
		}
		if(!"".equals(targetFeatureID)){
			updateFeature.setTargetFeatureID(targetFeatureID);
		}
		return Persistence_Helper_FeatureAssociation.getInstance().update(updateFeature);
	}
	
//	@MetaMethod
	@DynamoDBIgnore
	public static FeatureAssociation  delete(@MetaParam("TenantID") String tenant_id, @MetaParam("id") String id) throws Dynamo_DB_Functions_Exception {
		return Persistence_Helper_FeatureAssociation.getInstance().delete(tenant_id,id);
	}
	
	@DynamoDBIgnore
	public static Metadata getMetadata(){
		return ClassSpy.getMetadata("data.features.FeatureAssociation");
	}
}


